import QtQuick 1.1
import com.nokia.symbian 1.1
import "core.js" as Core
import "settings.js" as Settings
import QtQuick 1.0

Page {

    id: settingsPage

    TitleHeader {
        id: listHeader
        text: "Settings"
    }

    BorderImage {
        id: border_image1
        x: -11
        y: 50
        width: 360
        height: 485
        source: "bkg2.png"

        Grid {
            id: grid1
            x: 40
            y: 94
            width: 314
            height: 400
            rows: 5
            columns: 1

            Text {
                id: text3
                x: 33
                y: 18
                color: platformStyle.colorNormalLight
                text: qsTr("Fuel Rate ( cost/unit )")
                font.pixelSize: 18
            }

            TextField {
                id: textFuelRate
                y: 234
                width: 180
                height: 50
                text: ""
                anchors.left: parent.left
                anchors.leftMargin: 11
                placeholderText: "Fule Rate"
                inputMask: ""
            }


            Text {
                id: text1
                x: 24
                y: 27
                color: platformStyle.colorNormalLight
                text: qsTr("Select View Type")
                font.pixelSize: 18
            }

            SelectionListItem {
                id: itemSelectionViewType
                x: 0
                y: 189
                implicitWidth: 300
                title: viewTypeDialog.model.get(0).name
                onClicked: viewTypeDialog.open()

                BoxSelectionDialog2 {
                    id: viewTypeDialog
                    x: 53
                    y: 84
                    titleText: "Select View Type"

                    onAccepted :{
                        itemSelectionViewType.title = model.get(selectedIndex).name;
                        Settings.setSetting("viewType",model.get(selectedIndex).name);
                       // boxId = model.get(selectedIndex).boxId;
                    }
                }
            }

            Text {
                id: text2
                x: 33
                y: 18
                color: platformStyle.colorNormalLight
                text: qsTr("Select Currency")
                font.pixelSize: 18
            }

            SelectionListItem {
                id:itemSelectionCurr
                x: 0
                y: 196
                implicitWidth: 300
                title: currencyDialog.model.get(0).name
                onClicked: currencyDialog.open()

                BoxSelectionDialog {
                    id: currencyDialog
                    x: 0
                    y: 0
                    titleText: "Select Currency"

                    onAccepted :{
                        itemSelectionCurr.title = model.get(selectedIndex).name;
                        Settings.setSetting("currency",model.get(selectedIndex).name);
                       // boxId = model.get(selectedIndex).boxId;
                    }
                }
            }

        }
    }

    tools: ToolBarLayout {
        ToolButton {iconSource: "toolbar-back"; onClicked: {saveAndBack()} }
    }
    function saveAndBack()
    {
        Settings.setSetting("rate",textFuelRate.text);
        pageStack.pop();
    }

    Component.onCompleted: {

        Settings.initialize();
                // Sets a value in the database
        var data = Settings.getSetting("viewType");
        if(data !== "0")
            itemSelectionViewType.title = data;
        else
            itemSelectionViewType.title = "All Time";



        data = Settings.getSetting("currency");
        if(data !== "0")
            itemSelectionCurr.title = data;
        else
            itemSelectionCurr.title = "USD";


        data = Settings.getSetting("rate");
        textFuelRate.text = data;

    }
}



